﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using StructureModelDeduction.Data;

namespace StructureModelDeduction.Kit
{
	internal class DeductionColumn
	{
		public DeductionColumn(Autodesk.Revit.DB.Document doc, Dictionary<ElementDataPack, List<ElementDataPack>> dicDeductionWall)
		{
			this.m_doc = doc;
			this.m_dicDeductionColumn = new Dictionary<ElementDataPack, List<ElementDataPack>>();
			this.m_dicDeductionColumn = dicDeductionWall;
		}

		public bool run()
		{
			List<ElementId> list = new List<ElementId>();
			try
			{
				foreach (KeyValuePair<ElementDataPack, List<ElementDataPack>> keyValuePair in this.m_dicDeductionColumn)
				{
					foreach (ElementDataPack elementDataPack in keyValuePair.Value)
					{
						ColumnDataPack CurrentColumnData = elementDataPack as ColumnDataPack;
						if (list.FindIndex((ElementId e) => e.IntegerValue == CurrentColumnData.SelfElementId.IntegerValue) == -1)
						{
							list.Add(CurrentColumnData.SelfElementId);
						}
					}
				}
				this.m_doc.Delete(list);
			}
			catch (Exception)
			{
				return false;
			}
			return true;
		}

		private Dictionary<ElementDataPack, List<ElementDataPack>> m_dicDeductionColumn;

		private Document m_doc;
	}
}
